import { defineStore } from 'pinia'

export const useBaseStore = defineStore('base',{
    state() {
      return {
          token:sessionStorage.getItem('token') || "",
          user:JSON.parse(sessionStorage.getItem('user')) || {},
          menus:[],
      }
    },
  actions: {
      setLoginData ( token="",user={} ) {
        this.token = token;
        sessionStorage.setItem('token',token);
        this.user = user;
        sessionStorage.setItem('user',JSON.stringify(user));
      },
      clearLoginData () {
        this.token = "";
        this.user = {};
        this.menus = [];
        sessionStorage.clear();
      }
  }
})
